import { AfterViewChecked, Component, ElementRef, EventEmitter, Injector, Output, ViewChild } from '@angular/core';
import { AppConsts } from '@shared/AppConsts';
import { AppComponentBase } from '@shared/common/app-component-base';
import { MessagesDto, MessagesServiceProxy} from '@shared/service-proxies/service-proxies';
import { ModalDirective } from 'ngx-bootstrap/modal';
import { map as _map, filter as _filter } from 'lodash-es';

@Component({
    selector: 'editMessageModal',
    templateUrl: './edit-message.component.html',
})
export class EditMessageModalComponent extends AppComponentBase {

    @ViewChild('editModal', { static: true }) modal: ModalDirective;
    @Output() modalSave: EventEmitter<any> = new EventEmitter<any>();

    saving = false;
    MessagesDto:MessagesDto = new MessagesDto();
    permissionDic:{ [key: string]: boolean; } = {};
    add:string

    constructor(
        injector: Injector,
        private _messagesServiceProxy: MessagesServiceProxy
    ) {
        super(injector);
    }

    show(id: string,kind:number,permissionDic:{ [key: string]: boolean; }): void {
        if (!id || !kind) {
           return;
        }
        this.permissionDic = permissionDic;
        this._messagesServiceProxy.getMessagesById(id,kind).subscribe(result=>{
            this.MessagesDto = result;
            this.add=result.province+"-"+result.city+"-"+result.area;
            this.modal.show();
        });
    }
    save(): void {
        this.saving = true;
        
    }

    close(): void {
        this.modal.hide();
    }    
}
